/* component */
import { BaseSelectUserNoDataView } from '@src/component/common/BaseSelectUser/components'
/* enum */
import { BaseSelectUserComponentNameEnum } from '@src/component/common/BaseSelectUser/model'
/* hooks */
import { useBaseSelectUserOptions, useSelectUserCheckedItemList } from '@src/component/common/BaseSelectUser/hooks'
/* scss */
import '@src/component/common/BaseSelectUser/components/Dynamic/index.scss'
/* vue */
// @ts-ignore
import { ComponentInstance, ComponentRenderProxy, defineComponent, inject  } from 'vue'
import { CommonComponentInstance } from '@model/VC'
import { CreateElement } from 'vue'

export type DynamicProps = {

}

export interface DynamicSetupState {
  
}

export enum DynamicEmitEventNameEnum {
  AddUser = 'add',
  RemoveUser = 'remove'
}

export type DynamicEmitsOptions = {
  [DynamicEmitEventNameEnum.AddUser]: () => void;
  [DynamicEmitEventNameEnum.RemoveUser]: () => void;
}

export type DynamicInstance = ComponentInstance & DynamicSetupState
export type DynamicVM = ComponentRenderProxy<DynamicProps, {}, {}, {}, {}, {}, {}, DynamicEmitsOptions> & CommonComponentInstance & DynamicInstance

export default defineComponent({
  name: BaseSelectUserComponentNameEnum.BaseSelectUserDynamic,
  emits: [
    DynamicEmitEventNameEnum.AddUser,
    DynamicEmitEventNameEnum.RemoveUser
  ],

  setup(props: DynamicProps, { emit }) {
    const { renderDynamicContent, isTrigger, CustomOptions } = useBaseSelectUserOptions()
    // 已选中数据
    const { checkedItemList, checkedItemListForComponent, checkedItemListIdMap, isSelectedByUserId, updateCheckedItem } = useSelectUserCheckedItemList()
    return {
      isTrigger,
      CustomOptions,
      renderDynamicContent,
      updateCheckedItem,
      checkedItemList,
      checkedItemListForComponent,
      checkedItemListIdMap,
      isSelectedByUserId
    }
    
  },
  render(h: CreateElement) {
    return (
      <div class={BaseSelectUserComponentNameEnum.BaseSelectUserDynamic}>
        {this.renderDynamicContent ? (
          this.renderDynamicContent(h, this, this.CustomOptions)
        ) : (
          <BaseSelectUserNoDataView />
        )}
        
      </div>
    )
  }
})
